﻿using System;
using fastCSharp;
using fastCSharp.code.cSharp;

namespace diantou.web.exam
{
    /// <summary>
    /// 完成答卷后发简历的考试/考生熟悉环境的测试赛/预先注册的考试
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class register : view<register>
    {
        /// <summary>
        /// 企业考试邀请
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private new diantou.examDataAccess.examInvitation user
        {
            get { return diantou.examDataAccess.examInvitation.Test; }
        }
        /// <summary>
        /// 企业考试
        /// </summary>
        /// <returns>是否成功</returns>
        private bool loadView(int examId)
        {
            if(load(examId))
            {
                switch (exam.Type)
                {
                    case dataModel.exam.type.考生熟悉环境的测试赛:
                        if (base.user != null && examUser.ExamId == examId && examUser.IsRegister)
                        {
                            if (examUser.ExamTime != fastCSharp.pub.MinTime)
                            {
                                if (!examUser.IsSubmit && examUser.SubmitTime > date.NowSecond)
                                {
                                    location(new diantou.dataModel.path.exam { Id = examId }.Problem);
                                    return false;
                                }
                                if (examUser.IsJudged)
                                {
                                    location(new diantou.dataModel.path.examUser { Id = examUser.Id }.ExamReport);
                                    return false;
                                }
                            }
                            location(new diantou.dataModel.path.exam { Id = examId }.Description);
                            return false;
                        }
                        return true;
                    case dataModel.exam.type.完成答卷后发简历的考试:
                    case dataModel.exam.type.预先注册的考试:
                        if (base.user != null && examUser.ExamId == examId && examUser.IsRegister)
                        {
                            if (examUser.ExamTime != fastCSharp.pub.MinTime && !examUser.IsSubmit && examUser.SubmitTime > date.NowSecond)
                            {
                                location(new diantou.dataModel.path.exam { Id = examId }.Problem);
                            }
                            else location(new diantou.dataModel.path.exam { Id = examId }.Description);
                            return false;
                        }
                        if (exam.UserCount < exam.MaxUserCount) return true;
                        AjaxResponse(webConfig.NotFound404);
                        return false;
                    default: location(exam.Path.Index); break;
                }
            }
            return false;
        }
    }
}
